﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Data;
using System.Windows.Forms;
using System.Data.SqlClient;
using DTO;

namespace DAO
{
    public class CT_BCDTTheoMatDoSuDungPhongDAO
    {
        public class SqlConnectionData
        {
            public static SqlConnection Connection()
            {
                SqlConnection conn = new SqlConnection(@"Data Source=.\SQLEXPRESS;Initial Catalog=QLKS;Integrated Security=True");
                return conn;
            }
        }

        //public static void InserCT_BCDTTheoMatDoSuDungPhong(CT_BCDTTheoMatDoSuDungPhongDTO ct)
        //{
        //    SqlConnection conn = SqlConnectionData.Connection();
        //    SqlCommand cmd = new SqlCommand("sp_InsertCT_BCDTTheoMatDoSuDungPhong", conn);
        //    cmd.CommandType = CommandType.StoredProcedure;
        //    cmd.Parameters.Add("@MaBCMD", SqlDbType.Int);
        //    cmd.Parameters.Add("@MaPhong", SqlDbType.Int);
        //    cmd.Parameters.Add("@SoNgayThue", SqlDbType.Int);
        //    cmd.Parameters.Add("@TyLe", SqlDbType.Float);
        //    cmd.Parameters["@MaBCMD"].Value = ct.MaBCMD;
        //    cmd.Parameters["@MaPhong"].Value = ct.MaPhong;
        //    cmd.Parameters["@SoNgayThue"].Value = ct.SoNgayThue;
        //    cmd.Parameters["@TyLe"].Value = ct.TyLe;
        //    conn.Open();
        //    cmd.ExecuteNonQuery();
        //    conn.Close();
        //}
        public static void LayChiTietBaoCaoDoanhThuTheoMatDo(int[] cacMaBCMD, ListView lv)
        {
            for (int i = 0; i < cacMaBCMD.Length; i++)
            {
                string sql = "Select p.TenPhong, ct.SoNgayThue, ct.TyLe From CT_BCDTTHEOMATDOSUDUNGPHONG ct, PHONG p Where ct.MaPhong=p.MaPhong and ct.MaBCMD=" + cacMaBCMD[i];
                DataTable dt = DataProvider.ExecuteQuery(sql);
                int stt = 1;
                foreach (DataRow dr in dt.Rows)
                {
                    ListViewItem lvit = new ListViewItem(stt.ToString());
                    for (int j = 0; j < dt.Columns.Count; j++)
                    {
                        if (j == dt.Columns.Count - 1)
                        {
                            lvit.SubItems.Add(dr[j].ToString() + " %");
                            break;
                        }
                        lvit.SubItems.Add(dr[j].ToString());
                    }
                    lv.Items.Add(lvit);
                    stt++;
                }
            }
        }

        public static DataTable GetAll()
        {
            string sql = "Select * From CT_BCDTTHEOMATDOSUDUNGPHONG";
            DataTable dt = DataProvider.ExecuteQuery(sql);
            return dt;
        }

        public static void InserCT_BCDTTheoMatDoSuDungPhong(CT_BCDTTheoMatDoSuDungPhongDTO ctmd)
        {
            string sql = string.Format("INSERT INTO CT_BCDTTHEOMATDOSUDUNGPHONG ( MaBCMD, MaPhong, SoNgayThue, TyLe) VALUES (" + ctmd.MaBCMD + ", " + ctmd.MaPhong + ", " + ctmd.SoNgayThue + ", " + ctmd.TyLe + ")");
            DataProvider.ExecuteNonQuery(sql);
        }
    }
}
